import tkinter as tk

class LeadIDObj:
    Offset = 20
    FontSize = 20
    Font = 'Helvetica'
    FontBold = ''

    def __init__(self, canvas, edge_pos, location, id_value):
        self.canvas = canvas
        self.edge_pos = edge_pos.upper()
        self.location = location
        self.id_value = id_value

#   def show(self):
        x, y = self.location

        # Determine the text and its position based on edge_pos
        if self.edge_pos == 'R':
            text_x = x - LeadIDObj.Offset
            text_y = y
            anchor = 'e'  # Right align
        elif self.edge_pos == 'L':
            text_x = x + LeadIDObj.Offset
            text_y = y
            anchor = 'w'  # Left align
        elif self.edge_pos == 'U':
            text_x = x
            text_y = y + LeadIDObj.Offset
            anchor = 'n'  # Top align
        elif self.edge_pos == 'D':
            text_x = x
            text_y = y - LeadIDObj.Offset
            anchor = 's'  # Bottom align
        else:
            raise ValueError(f"Invalid edge_pos: {self.edge_pos}")

        # Create the text
        _x = int(text_x)
        _y = int(text_y)
        self.canvas.create_text(
            _x, _y,
            text=str(self.id_value),
            font=(LeadIDObj.Font, LeadIDObj.FontSize, LeadIDObj.FontBold),
            anchor=anchor,
            fill='black'
        )

if __name__ == "__main__":
    # Create main window
    root = tk.Tk()
    root.title("LeadIDObj Example")

    # Create a canvas
    canvas = tk.Canvas(root, width=800, height=600)
    canvas.pack()

    # Define the reference point
    reference_point = (200, 200)

    # Draw a red dot at the reference point
    dot_size = 5
    canvas.create_oval(reference_point[0] - dot_size, reference_point[1] - dot_size,
                    reference_point[0] + dot_size, reference_point[1] + dot_size,
                    fill='red', outline='red')

    # Define locations and edges for each LeadIDObj
    locations_edges_ids = [
        (reference_point, 'L', 11),  # Left
        (reference_point, 'R', 12), # Right
        (reference_point, 'U', 13), # Up
        (reference_point, 'D', 14)  # Down
    ]

    # Create LeadIDObj instances at specified locations and edges
    lead_id_objs = []
    for loc, edge, id_val in locations_edges_ids:
        lead_id_obj = LeadIDObj(canvas, edge_pos=edge, location=loc, id_value=id_val)
        lead_id_objs.append(lead_id_obj)

    LeadIDObj.Offset = 100
    # Show all LeadIDObj instances
#    for lead_id_obj in lead_id_objs:
#        lead_id_obj.show()

    # Run main loop
    root.mainloop()



